import Vue from "vue";

import "normalize.css/normalize.css"; // A modern alternative to CSS resets

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import locale from "element-ui/lib/locale/lang/en"; // lang i18n

import "@/styles/index.scss"; // global css

import App from "./App";
import store from "./store";
import router from "./router";
import "animate.css"; // 引入animate.css

import "@/icons"; // icon
import "@/permission"; // permission control
import permissionDirective from "@/directives/permission"; // 权限指令

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === "production") {
  const { mockXHR } = require("../mock");
  mockXHR();
}
Vue.directive("animate", {
  inserted: function (el, binding) {
    const options = {
      root: null, // 相对于视口
      rootMargin: "0px",
      threshold: 0.01, // 当1%的元素可见时触发
    };
    const observer = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          el.classList.add(binding.value);
          // 如果需要只触发一次，可以取消观察
          observer.unobserve(el);
        } else {
          // 可选：离开可视区域时移除类名
          // el.classList.remove(binding.value);
        }
      });
    }, options);
    observer.observe(el);

    // 保存观察器实例以便后续清理
    el._intersectionObserver = observer;
  },

  unbind(el) {
    if (el._intersectionObserver) {
      el._intersectionObserver.disconnect();
    }
  },
});
// set ElementUI lang to EN
// Vue.use(ElementUI, { locale });
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

// 注册权限指令
Vue.use(permissionDirective)

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
});
